Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    message: {
      type: String,
      value: ''
    }
  },

  data: {
    animationData: {}
  },

  methods: {
    showToast(message, duration = 2000) {
      // 创建动画实例
      const animation = wx.createAnimation({
        duration: 300,
        timingFunction: 'cubic-bezier(0.68, -0.55, 0.265, 1.55)',
        delay: 0
      });

      // 设置初始状态
      animation.opacity(0).scale(0).step({duration: 0});
      
      this.setData({
        show: true,
        message,
        animationData: animation.export()
      });

      // 立即执行显示动画
      setTimeout(() => {
        animation.opacity(1).scale(1.1).step({duration: 200});
        animation.scale(1).step({duration: 100});
        
        this.setData({
          animationData: animation.export()
        });
      }, 50);

      // 根据传入的duration执行隐藏动画
      setTimeout(() => {
        animation.opacity(0).scale(0.8).step({duration: 200});
        
        this.setData({
          animationData: animation.export()
        });

        setTimeout(() => {
          this.setData({
            show: false
          });
          this.triggerEvent('onHide');
        }, 200);
      }, duration);
    }
  }
});